package com.concurrent.chapter9.concurrent02;

import java.util.concurrent.RecursiveAction;

public class MyRecursiveAction extends RecursiveAction {

	private int beginValue;
	private int endValue;
	
	public MyRecursiveAction(int beginValue, int endValue) {
		super();
		this.beginValue = beginValue;
		this.endValue = endValue;
	}
	@Override
	protected void compute() {
		System.out.println("MyRecursiveAction.compute()----" + Thread.currentThread().getName());
		if (endValue - beginValue > 2) {
			int middleValue = (beginValue + endValue)/2;
			MyRecursiveAction leftAction = new MyRecursiveAction(beginValue, middleValue);
			MyRecursiveAction rightAction = new MyRecursiveAction(middleValue + 1, endValue);
			invokeAll(leftAction, rightAction);
		} else {
			System.out.println("组合result:" + beginValue + "--" + endValue);
		}
	}
}
